-use serialize::Decodable;
use std::collections::HashMap;
use std::fmt;
use std::io::fs;
use std::slice;
use std::str;
use toml;
+use semver;
+use serialize::{Decodable, Decoder};
use core::{SourceId, GitKind};
use core::manifest::{LibKind, Lib, Dylib, Profile};
* TODO: Make all struct fields private
*/
-#[deriving(Encodable,Decodable,PartialEq,Clone,Show)]
+#[deriving(Decodable)]
pub enum TomlDependency {
SimpleDep(String),
DetailedDep(DetailedTomlDependency)
}
-#[deriving(Encodable,Decodable,PartialEq,Clone,Show)]
+#[deriving(Decodable)]
pub struct DetailedTomlDependency {
version: Option<String>,
path: Option<String>,
rev: Option<String>
}
-#[deriving(Encodable,Decodable,PartialEq,Clone)]
+#[deriving(Decodable)]
pub struct TomlManifest {
package: Option<Box<TomlProject>>,
project: Option<Box<TomlProject>>,
dev_dependencies: Option<HashMap<String, TomlDependency>>,
}
-#[deriving(Encodable,Decodable,PartialEq,Clone)]
+#[deriving(Decodable)]
pub enum ManyOrOne<T> {
Many(Vec<T>),
One(T),
}
}
-#[deriving(Decodable,Encodable,PartialEq,Clone,Show)]
+#[deriving(Decodable)]
pub struct TomlProject {
- pub name: String,
- // FIXME #54: should be a Version to be able to be Decodable'd directly.
- pub version: String,
+ name: String,
+ version: TomlVersion,
pub authors: Vec<String>,
build: Option<TomlBuildCommandsList>,
exclude: Option<Vec<String>>,
}
-#[deriving(Encodable,Decodable,PartialEq,Clone,Show)]
+#[deriving(Decodable)]
pub enum TomlBuildCommandsList {
SingleBuildCommand(String),
MultipleBuildCommands(Vec<String>)
}
+pub struct TomlVersion {
+ version: semver::Version,
+}
+
+impl<E, D: Decoder<E>> Decodable<D, E> for TomlVersion {
+ fn decode(d: &mut D) -> Result<TomlVersion, E> {
+ let s = raw_try!(d.read_str());
+ match semver::parse(s.as_slice()) {
+ Some(s) => Ok(TomlVersion { version: s }),
+ None => Err(d.error(format!("cannot parse '{}' as a semver",
+ s).as_slice())),
+ }
+ }
+}
+
impl TomlProject {
pub fn to_package_id(&self, source_id: &SourceId) -> CargoResult<PackageId> {
- PackageId::new(self.name.as_slice(), self.version.as_slice(), source_id)
+ PackageId::new(self.name.as_slice(), self.version.version.clone(),
+ source_id)
}
}
&metadata);
if targets.is_empty() {
- debug!("manifest has no build targets; project={}", self.project);
+ debug!("manifest has no build targets");
}
let mut deps = Vec::new();
Ok(())
}
-#[deriving(Decodable,Encodable,PartialEq,Clone,Show)]
+#[deriving(Decodable, Show, Clone)]
struct TomlTarget {
name: String,
crate_type: Option<Vec<String>>,
plugin: Option<bool>,
}
-#[deriving(Decodable,Encodable,PartialEq,Clone)]
+#[deriving(Decodable, Clone)]
enum TomlPath {
TomlString(String),
TomlPath(Path),